# Let's define a Circle with properties x, y, and r, denoting the x and y position of the center of the circle, and its radius, respectively.
# You might want to have one signal that is emitted when the circle is resized, and another that is emitted when it is moved; we'll call them 
# resized and moved, respectively.
# It would be possible to have the slots to which the resized and moved signals are connected check the new position or size of the circle and 
# respond accordingly, but it's more convenient and requires less knowledge of circles by the slot functions if the signal that is sent can 
# include that information.

from __future__ import print_function
import sys
from PySide import QtCore, QtGui
  
class Circle(QtCore.QObject):
    # Represents a circle defined by the x and y coordinates of its center and its radius r.
    # Signal emitted when the circle is resized, carrying its integer radius
    resized = QtCore.Signal(int)
    # Signal emitted when the circle is moved, carrying the x and y coordinates of its center.
    moved = QtCore.Signal(int, int)
  
    def __init__(self, x, y, r):
        # Initialize the Circle as a QObject so it can emit signals
        QtCore.QObject.__init__(self)
  
        # "Hide" the values and expose them via properties
        self._x = x
        self._y = y
        self._r = r
  
    @property
    def x(self):
        return self._x
  
    @x.setter
    def x(self, new_x):
        self._x = new_x
        # After the center is moved, emit the moved signal with the new coordinates
        self.moved.emit(new_x, self.y)
  
    @property
    def y(self):
        return self._y
    @y.setter
    def y(self, new_y):
        self._y = new_y
        # After the center is moved, emit the moved signal with the new coordinates
        self.moved.emit(self.x, new_y)
  
    @property
    def r(self):
        return self._r
  
    @r.setter
    def r(self, new_r):
        self._r = new_r
    # After the radius is changed, emit the resized signal with the new radius
        self.resized.emit(new_r)
         
# Now, let's define some slots that can be connected to the Circle's signals. Remember last time, when we said we'd see more about the @Slot 
# decorator? We now have signals that carry data, so we'll see how to make slots that can receive it. To make a slot accept data from a signal, 
# we simply define it with the same signature as its signal.
# A slot for the "moved" signal, accepting the x and y coordinates
@QtCore.Slot(int, int)
def on_moved(x, y):
    print('Circle was moved to (%s, %s).' % (x, y))
  
# A slot for the "resized" signal, accepting the radius
@QtCore.Slot(int)    
def on_resized(r):
    print('Circle was resized to radius %s.' % r)
c = Circle(5, 5, 4)
  
# Connect the Circle's signals to our simple slots
c.moved.connect(on_moved)
c.resized.connect(on_resized)
  
# Move the circle one unit to the right
c.x += 1
  
# Increase the circle's radius by one unit
c.r += 1